import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

// import Layout from '@/views/Layout/Index.vue'

const constantRoutes: Array<RouteRecordRaw> = [
  {
    path: '/screen',
    name: 'Screen',
    meta: { title: '大屏' },
    component: () => import('@/views/screen/Index.vue')
  },
  {
    path: '/',
    name: '',
    meta: { title: '首页' },
    component: () => import('@/views/home/layout/Index.vue'),
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        meta: { title: '首页' },
        component: () => import('@/views/home/Index.vue'),
      },
    ]
  },
  {
    path: '/admin',
    name: '',
    meta: { title: '首页' },
    component: () => import('@/views/layout/Index.vue'),
    redirect: '/admin/dashboard',
    
    children: [
      
      {
        path: 'dashboard',
        name: 'Dashboard',
        meta: { title: '首页' },
        component: () => import('@/views/dashboard/Index.vue')
      },
      {
        path: 'appraisal',
        name: 'Appraisal',
        meta: { title: 'QQ评估' },
        component: () => import('@/views/appraisal/Index.vue')
      },
      {
        path: 'system',
        name: 'system',
        meta: { title: '系统管理' },
        redirect: '/system/user',
        children: [
          {
            path: 'menu',
            name: 'menu',
            meta: { title: '菜单管理' },
            component: () => import('@/views/system/menu/Index.vue')
          },
          {
            path: 'user',
            name: 'User',
            meta: { title: '用户管理' },
            component: () => import('@/views/system/user/Index.vue')
          },
        ]
      },
      
    ]
  },
  {
    path: '/auth-login',
    name: 'authLogin',
    meta: { title: '首页' },
    component: () => import('@/views/auth/Login.vue'),
  }
]

const router = createRouter({
  history: createWebHistory(), // 不带 # 号
  // history: createWebHistory('/admin/'), // 不带 # 号
  // history: createWebHashHistory(), // 带 # 号
  routes: constantRoutes
})

// 路由跳转前的监听操作
router.beforeEach((to, from, next) => {
  // 修改title
  document.title = '货架安全监测预警系统'
  next()
})

export default router
